<%@ Page Title="" Language="C#" MasterPageFile="~/Rtgs.master" AutoEventWireup="true"
    CodeFile="stpReason_Pages.aspx.cs" Inherits="RTGS.Web.page.rtgs.stpReason_Pages" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/css/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/i18n/grid.locale-en.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveClientUrl("~/script/helper.js") %>" type="text/javascript"></script>
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/jquery.fmatter.js") %>"></script>
    <script type="text/javascript" language="javascript">
        $(function () {
            $("#table").jqGrid({
                url: '../../Ajaxhandler/RTGS/stp_Reason.ashx?method=getdata',
                datatype: 'json',
                colNames: ['Reason Code',
'Reason Desc.'],
                colModel: [
{ name: 'reasonid', hidden: false, index: 'ReasonID', width: 100 },
{ name: 'reasondesc', hidden: false, index: 'ReasonDesc', width: 200 }
		],
                rowNum: 10,
                id: 'ReasonID',
                multiselect: true,
                rowList: [5, 10, 15, 20],
                pager: '#pager',
                sortname: 'ReasonID',
                sortorder: "asc",
                viewrecords: true,
                jsonReader: { repeatitems: false },
                width: 600,
                height: '100%',
                caption: 'Reason',
                ajaxGridOptions: { cache: false },
                ondblClickRow: function () {
                    OpenForm('edit');
                }
            });


        });


        function OpenForm(ctl) {
            var grid = $("#table");
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
			selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'reasonid'));
            });


            if (ctl == "edit") {
                if (selIds.length == 0) {
                }
                else if (selIds.length > 1) {
                    alert('Pilih satu record untuk ubah data.');
                }
                else {
                   
                    $("#dialog").load('../../Form/RTGS/stpReason_Form.aspx?Id=' + encodeURIComponent(selText)).dialog({ modal: true, width: 600, height: 170, title: 'Edit Data' });
                }
            }
            else if (ctl == "add") {
                $("#dialog").load('../../Form/RTGS/stpReason_Form.aspx').dialog({ modal: true, width: 600, height: 170, title: 'Add Data' });
            }
            else {
                var result = window.confirm('Are you sure that you want to delete?');
                if (result) {
                    CallAjax("../../ajaxhandler/RTGS/stp_Reason.ashx", "?method=delete" + "&id=" + encodeURIComponent(selText));
                    setTimeout("$('#table').trigger('reloadGrid');", 3000);
                }
            }
        }
    </script>
    <div>
        <a href="javascript:void(0);" id="dialog_link_add" class="dialog_link ui-state-default ui-corner-all"
            onclick="OpenForm('add')" title="Add"><span class="ui-icon ui-icon-plus"></span>
            Add</a> <a href="javascript:void(0);" id="dialog_link_edit" class="dialog_link ui-state-default ui-corner-all"
                onclick="OpenForm('edit')" title="Edit"><span class="ui-icon ui-icon-plus"></span>
                Edit</a> <a href="javascript:void(0);" id="dialog_link_delete" class="dialog_link ui-state-default ui-corner-all"
                    onclick="OpenForm('delete')" title="Delete"><span class="ui-icon ui-icon-plus"></span>
                    Delete</a>
    </div>
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
</asp:Content>
